﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace E1_eMart.admin
{
    public partial class sales_report : System.Web.UI.Page
    {
        protected List<SanPham> listSP = new List<SanPham>();
        protected string str = "str";

        protected void Page_Load(object sender, EventArgs e)
        {
            DataClasses1DataContext edata = new DataClasses1DataContext();
            int id = 0;
            List<SanPham> list = edata.SanPhams.ToList<SanPham>();
            
            for (int i = 0; i < list.Count; i++)
            {
                if (id == 0)// trong ngay
                {
                    if (ProductInToday(list[i]))
                        listSP.Add(list[i]);
                }
                else if (id == 1)//trong thang
                {
                    if(ProductInThisMonth(list[i]))
                    listSP.Add(list[i]);
                }
                else// trong nam
                {
                    if(ProductInThisYear(list[i]))
                    listSP.Add(list[i]);
                }
            }
        }

        private Boolean ProductInThisMonth(SanPham sp)
        {
            DateTime dateNow = DateTime.Now;
            int thisMonth = dateNow.Month;
            int thisYear = dateNow.Year;
            int year = sp.NgayDang.Value.Year;
            int month = sp.NgayDang.Value.Month;
            if (thisMonth == month && thisYear == year)
            return true;
            return false;
        }

        private Boolean ProductInThisYear(SanPham sp)
        {
            

            DateTime dateNow = DateTime.Now;
            int thisYear = dateNow.Year;
            int year = sp.NgayDang.Value.Year;
            if (thisYear == year)
                return true;
            return false;
        }

        private Boolean ProductInToday(SanPham sp)
        {
            DateTime dateNow = DateTime.Now;
            int thisMonth = dateNow.Month;
            int thisYear = dateNow.Year;
            int thisDay = dateNow.Day;
            int year = sp.NgayDang.Value.Year;
            int month = sp.NgayDang.Value.Month;
            int day = sp.NgayDang.Value.Day;
            if (thisMonth == month && thisYear == year && day == thisDay)
                return true;
            return false;
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataClasses1DataContext edata = new DataClasses1DataContext();
            int id = 0;
            List<SanPham> list = edata.SanPhams.ToList<SanPham>();
            for (int i = 0; i < list.Count; i++)
            {
                if (id == 0)// trong ngay
                {
                    if (ProductInToday(list[i]))
                        listSP.Add(list[i]);
                }
                else if (id == 1)//trong thang
                {
                    if (ProductInThisMonth(list[i]))
                        listSP.Add(list[i]);
                }
                else// trong nam
                {
                    if (ProductInThisYear(list[i]))
                        listSP.Add(list[i]);
                }
            }
        }
    }
}